﻿using System;
using System.Collections.Generic;
using System.Net;
using System.Xml;

using FRL.DebtChased.Extensions;

namespace FRL.DebtChased.WorkflowEditor
{

	/// <summary>
	/// Declaration of WorkflowActionResult class
	/// </summary>
	public class WorkflowActionResult
	{

		/////////////////////////////////////////////////////////////
		// Constants

		public const string ElementName = "WorkflowActionResult";

		/////////////////////////////////////////////////////////////
		// Attributes

		private string m_strValue;
		public string Value
		{
			get { return m_strValue; }
			set { m_strValue = value; }
		}

		private WorkflowAction_Base m_nextAction;
		public WorkflowAction_Base NextAction
		{
			get { return m_nextAction; }
			set { m_nextAction = value; }
		}

		private double m_dblDesignLocationX;
		public double DesignLocationX
		{
			get { return m_dblDesignLocationX; }
			set { m_dblDesignLocationX = value; }
		}

		private double m_dblDesignLocationY;
		public double DesignLocationY
		{
			get { return m_dblDesignLocationY; }
			set { m_dblDesignLocationY = value; }
		}

		/////////////////////////////////////////////////////////////
		// Construction

		public WorkflowActionResult(string strValue, WorkflowAction_Base nextAction)
		{

			// Initialize member variables
			m_strValue = strValue;
			m_nextAction = nextAction;

		}

		/////////////////////////////////////////////////////////////
		// Serialization

		public void ToXml(XmlWriter w, Dictionary<Guid, WorkflowAction_Base> ActionMap)
		{

			/*
			// Write an element
			w.WriteStartElement(ElementName);
			{

				// Write attributes
				w.WriteAttributeString("value", m_strValue);
				w.WriteAttributeString("designLocationX", m_dblDesignLocationX.ToString());
				w.WriteAttributeString("designLocationY", m_dblDesignLocationY.ToString());				

				// If there is a link...
				if (this.m_nextAction != null)
				{

					// Reverse lookup of key
					Guid Key = Guid.Empty;
					foreach (var di in ItemMap)
					{
						if (di.Value == this.m_nextItem)
						{
							Key = di.Key;
							break;
						}
					}
					w.WriteAttributeString("key", Key.ToString());

				}

			}
			w.WriteEndElement();
			 */

		}

		public static WorkflowActionResult XmlFactory(XmlReader r, Dictionary<Guid, WorkflowAction_Base> ActionMap)
		{

			/*
			// Read attributes
			string strValue = r.GetAttribute("value");
			double dblDesignLocationX = r.SafeReadDoubleAttribute("designLocationX", 0);
			double dblDesignLocationY = r.SafeReadDoubleAttribute("designLocationY", 0);
			string strKey = r.GetAttribute("key");

			// Get the next item
			WorkflowTemplateItem_Base nextItem = null;
			if (strKey != null)
			{
				Guid uidKey = new Guid(strKey);
				nextItem = ItemMap[uidKey];
			}

			// Declare return variable
			WorkflowTemplateResult Ftmp = new WorkflowTemplateResult(strValue,nextItem);
			Ftmp.DesignLocationX = dblDesignLocationX;
			Ftmp.DesignLocationY = dblDesignLocationY;

			// Return variable
			return Ftmp;
			 */
			return null;

		}

	}

}
